﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.Adbanner
{
    public partial class AdbannerMasterForm : BasicPage
    {
        public int pcount = 0; //总条数
        public int page; //当前页
        public readonly int pagesize = 15; //设置每页显示的大小
        private readonly AdbannerBLL _bll = new AdbannerBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
            chkLoginLevel("viewAdbanner");
            RptBind();
        }

        #region 列表数据绑定
        private void RptBind()
        {
            if (!int.TryParse(Request.Params["page"] as string, out this.page))
            {
                this.page = 0;
            }
            this.pcount = _bll.GetCount();
            this.lbtnDel.Enabled = this.pcount > 0;
            this.rptList.DataSource = _bll.GetPageList(this.pagesize, this.page);
            this.rptList.DataBind();
        }
        #endregion

        protected string GetStatus(string strLock)
        {
            return int.Parse(strLock) == 1 ? "<font color=\"#999999\">暂停</font>" : "<font color=\"#009900\">正常</font>";
        }

        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delAdbanner");
            var list = new List<AdbannerInfo>();  
            for (var i = 0; i < rptList.Items.Count; i++)
            {
                var id = ((Label)rptList.Items[i].FindControl("lb_id")).Text;
                var cb = (CheckBox)rptList.Items[i].FindControl("cb_id");
                if (!cb.Checked) continue;
                var model = new AdbannerInfo {Id = id};
                list.Add(model);
            }
            if (_bll.Delete(list))
            {
                JscriptPrint("批量删除成功！", "AdbannerMasterForm.aspx", "Success");
            }
            else
            {
                JscriptPrint("删除失败！", "AdbannerMasterForm.aspx", "Error");
            }
            
        }
    }
}